class CategoriesController < ApplicationController
  before_filter :find_category, :only => [:show, :edit, :update, :destroy]
  before_filter :login_required, :only => [:create, :edit, :new, :update, :destroy]
  
  # GET, events_url
  def index
    @categories = (Category.find :all)
  end
  
  # GET, event_url
  def show
  end
  
  # GET, new_event_url
  def new
    @category = Category.new
  end
  
  # POST, events_url
  def create
    @category = Category.new(params[:category])
    @category.save!
    redirect_to category_url(@category.id)
  rescue ActiveRecord::RecordInvalid
    flash[:error] = 'Nice one, jackass.'
    render :action => 'new'
  end
  
  # GET, edit_event_url
  def edit
  end
  
  # PUT, event_url
  def update
    @category.update_attributes!(params[:category])
    redirect_to category_url
  rescue ActiveRecord::RecordInvalid
    flash[:error] = 'Nice one, jackass'
    render :action => 'edit'
  end
  
  # DELETE, event_url
  def destroy
    @category.destroy
    redirect_to categories_url
  end
  
  def reroute
    redirect_to category_url(params[:id])
  end
  
protected
  def find_category
    @category = Category.find params[:id]
  end
end
